﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HonBlogPub.Util
{
    class TextBoxUtil
    {
        private const int EM_LINEINDEX = 0xBB;
        private const int EM_LINEFROMCHAR = 0xC9;
        private const int EM_GETSEL = 0xB0;

        internal static int GetCurrentLine(TextBox txtBox)
        {
            if (null == txtBox || !txtBox.IsHandleCreated)
                throw new InvalidOperationException("txtBox invalid");

            IntPtr handle = txtBox.Handle;

            int l;

            l = NativeMethods.SendMessage(handle, EM_LINEINDEX, -1, 0);
            return NativeMethods.SendMessage(handle, EM_LINEFROMCHAR, l, 0);
        }
    }
}
